package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.bean.RecommendSceneBean;

import java.util.List;

/**
 * author : Android 轮子哥
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2019/09/22
 * desc   : 状态数据列表
 */
public final class RecommendSceneAdapter extends AppAdapter<RecommendSceneBean> {

    public RecommendSceneAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    @Override
    public void setData(@Nullable List<RecommendSceneBean> data) {
        super.setData(data);
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvSceneName;
        private final TextView tvDescribe;

        private ViewHolder() {
            super(R.layout.item_recommend_scene);
            tvSceneName = findViewById(R.id.tv_scene_name);
            tvDescribe = findViewById(R.id.tv_describe);
        }

        @Override
        public void onBindView(int position) {
            RecommendSceneBean scene = getItem(position);
            tvSceneName.setText(scene.getName());
            tvDescribe.setText(scene.getDescription());
            int res = getContext().getResources().getIdentifier(scene.getSmallImage(), "mipmap", getContext().getPackageName());
            if(res != 0){
                itemView.setBackgroundResource(res);
            }
//            GlideApp.with(getContext())
//                    .load(BuildConfig.APP_RESOURCE_BASE + scene.getImage())
//                    .into(new CustomTarget<Drawable>() {
//                        @Override
//                        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
//                            itemView.setBackground(resource);
//                        }
//
//                        @Override
//                        public void onLoadCleared(@Nullable Drawable placeholder) {
//
//                        }
//                    });
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}